@echo off
REM **************************************************************************/
REM This batch file is used to build the SOAP example applications that      */
REM demonstrate the Sh interface.                                            */
REM                                                                          */
REM It assumes that you have Sun's JDK installed (1.5), and have javac (the  */
REM Java compiler) and java (the Java interpreter) in your PATH.  You should */
REM also have both WSDL files (ShService.wsdl and ShServiceTyped.wsdl)       */
REM located two directories above here.                                      */
REM **************************************************************************/

set AXIS_JARS=axis\activation.jar;axis\axis-ant.jar;axis\axis-schema.jar;axis\axis.jar;axis\commons-discovery-0.2.jar;axis\commons-logging-1.0.4.jar;axis\jaxrpc.jar;axis\log4j-1.2.8.jar;axis\mailapi.jar;axis\saaj.jar;axis\wsdl4j-1.5.1.jar

if not exist soapstub (

   REM ***********************************************************************/
   REM Use Apache Axis' WSDL2Java tool to create stub code for accessing the */
   REM SOAP service.                                                         */
   REM                                                                       */
   REM Stub code for the "untyped" style will be written to the              */
   REM "soapstub\untyped" directory.  Code for the "typed" style will be     */
   REM written to "soapstub\typed".                                          */
   REM ***********************************************************************/

   echo Generating Java code.

   java -classpath %AXIS_JARS% org.apache.axis.wsdl.WSDL2Java ..\..\ShService.wsdl -o soapstub\untyped --NStoPkg http://www.metaswitch.com/ems/soap/sh=com.MetaSwitch.EMS.SOAP
   java -classpath %AXIS_JARS% org.apache.axis.wsdl.WSDL2Java ..\..\ShServiceTyped.wsdl -o soapstub\typed --NStoPkg http://www.metaswitch.com/ems/soap/sh=com.MetaSwitch.EMS.SOAP --NStoPkg http://www.metaswitch.com/ems/soap/sh/userdata=com.MetaSwitch.EMS.SOAP --NStoPkg http://www.metaswitch.com/ems/soap/sh/servicedata=com.MetaSwitch.EMS.SOAP

   REM ***********************************************************************/
   REM There's a bug in the WSDL2Java tool that means it generates invalid   */
   REM Java code.  The MetaSwitchData class has a constructor with masses of */
   REM parameters, one for each SI, and that's more than the 255 that Java   */
   REM allows.  We must tell the user to edit the generated code.            */
   REM ***********************************************************************/

   echo Java code generated from schema.
   echo.
   echo The code was generated by Axis2's WSDL2Java tool, which has a bug, and
   echo the code it produced is not valid Java.  Please manually edit the file
   echo soapstub\typed\com\MetaSwitch\EMS\SOAP\TMetaSwitchData.java
   echo.
   echo The class has two constructors, one with no parameters, and one with
   echo hundreds of parameters.  Please delete the constructor with hundreds of
   echo parameters.
   echo.
   echo Then run build.bat again.

) else (

   REM ***********************************************************************/
   REM Create binary directories and compile the stub code.                  */
   REM                                                                       */
   REM Class files will be written to the "classes" directory.               */
   REM ***********************************************************************/

   echo SOAP stub code exists - compiling.
   echo.
   echo If you have changed the MetaView Server name in ShService.wsdl or you have
   echo recently upgraded MetaView to a new version and need to use its new schema,
   echo please delete the directory 'soapstub' and run build.bat again.
   echo.

   mkdir classes 2>NUL
   mkdir classes\untyped 2>NUL
   mkdir classes\typed 2>NUL

   javac -classpath %AXIS_JARS%;classes\untyped -sourcepath soapstub\untyped -d classes\untyped soapstub\untyped\com\metaswitch\ems\soap\*.java 2>NUL
   javac -classpath %AXIS_JARS%;classes\typed -sourcepath soapstub\typed -d classes\typed soapstub\typed\com\metaswitch\ems\soap\*.java 2>NUL

   if not exist classes\typed\com\MetaSwitch\EMS\SOAP\TMetaSwitchData.class (

      REM ********************************************************************/
      REM The MetaSwitch Data class did not compile.  That is probably       */
      REM because it has a constructor with more parameters than Java        */
      REM allows, owing to a bug in the WSDL2Java tool, and the user has not */
      REM followed the instructions to fix it.  We repeat the instructions.  */
      REM ********************************************************************/

      echo Build failed.
      echo.
      echo You need to make a manual change to the auto-generated SOAP stub code.
      echo.
      echo The code was generated by Axis2's WSDL2Java tool, which has a bug, and
      echo the code it produced is not valid Java.  Please manually edit the file
      echo soapstub\typed\com\MetaSwitch\EMS\SOAP\TMetaSwitchData.java
      echo.
      echo The class has two constructors, one with no parameters, and one with
      echo hundreds of parameters.  Please delete the constructor with hundreds of
      echo parameters.
      echo.
      echo Then run build.bat again.

   ) else (

      REM ********************************************************************/
      REM Compile the example applications.                                  */
      REM                                                                    */
      REM Class files will be written to the "classes" directory.            */
      REM ********************************************************************/

      javac -classpath %AXIS_JARS%;classes\untyped;classes -d classes source\ShUtilities.java
      javac -classpath %AXIS_JARS%;classes\untyped;classes -d classes source\untyped\ShUntypedUtilities.java 2>NUL
      javac -classpath %AXIS_JARS%;classes\untyped;classes -d classes source\untyped\SimplePull.java
      javac -classpath %AXIS_JARS%;classes\untyped;classes -d classes source\untyped\UpdateSubscription.java
      javac -classpath %AXIS_JARS%;classes\untyped;classes -d classes source\untyped\DeleteSubscriber.java
      javac -classpath %AXIS_JARS%;classes\typed;classes -d classes source\typed\ShTypedUtilities.java
      javac -classpath %AXIS_JARS%;classes\typed;classes -d classes source\typed\UpdatePIN.java
      javac -classpath %AXIS_JARS%;classes\typed;classes -d classes source\typed\CreateSubscriber.java
      javac -classpath %AXIS_JARS%;classes\typed;classes -d classes source\typed\AddMandatoryAccountCode.java
      javac -classpath %AXIS_JARS%;classes\typed;classes -d classes source\typed\EnumerateSubscribers.java

      echo Build completed.
   )
)
